最近开始玩SpringMVC了,就首先得在自己的mac上把maven安装一下,一波三证还是出现了几个问题,还是记录一下分享给大家吧。。。

1、首先去官网下载 maven3.3.9,配置如下:

tar -zxvf apache-maven-3.3.9
sudo mv apache-maven-3.3.9 /usr/local/maven3.3.9
sudo vim ~/.bash_profile
...
M2_HOME="/usr/local/maven3.3.9/bin"
PATH=$PATH:$M2_HOME
export M2_HOME
export PATH
...

重新打开终端之后测试一把 mvn -v,报错如下:

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0

查了一下是maven版本和jdk版本不匹配导致的
要么升级jdk版本,要么换个低版本的maven试试(这里我采用这个方案)

2、重新下载 maven3.0.5

tar -zxvf apache-maven-3.0.5
sudo mv apache-maven-3.0.5 /usr/local/maven3.0.5
sudo vim ~/.bash_profile
...
M2_HOME="/usr/local/maven3.0.5/bin"
PATH=$PATH:$M2_HOME
export M2_HOME
export PATH
...

重新打开终端之后测试一把 mvn -v,报错如下:

Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/classwor
lds/Launcher 
Caused by: java.lang.ClassNotFoundException: org.codehaus.classworlds.Launcher 
        at java.net.URLClassLoader$1.run(Unknown Source) 
        at java.security.AccessController.doPrivileged(Native Method) 
        at java.net.URLClassLoader.findClass(Unknown Source) 
        at java.lang.ClassLoader.loadClass(Unknown Source) 
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
        at java.lang.ClassLoader.loadClass(Unknown Source) 
        at java.lang.ClassLoader.loadClassInternal(Unknown Source) 
Could not find the main class: org.codehaus.classworlds.Launcher.  Program will 
exit.

查了一下,是环境变量配置的问题,修改如下:

sudo vim ~/.bash_profile
...
#这里去掉后面的/bin
M2_HOME="/usr/local/maven3.0.5"
#这里M2_HOME变量后面加上/bin
PATH=$PATH:${M2_HOME}/bin
export M2_HOME
export PATH
...

最后重新打开终端之后测试一把 mvn -v

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 21:51:28+0800)
Maven home: /usr/local/maven3.0.5
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: zh_CN, platform encoding: EUC_CN
OS name: "mac os x", version: "10.11.3", arch: "x86_64", family: "mac"

杨佰
2.8k 声望43 粉丝

良好的心里,出众的发挥!